package tps.video_games;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.colissions.CollisionDetector;

public abstract class Pildora extends GameComponent<GameScene>{
	
	int diameter = 10;
	
	public Pildora(Color color) {
		this.setAppearance(new Circle(color, this.diameter));
	}
	
	public abstract void ejecutar();
	
	@Override
	public void update(DeltaState deltaState) {
		this.move(0,10);
		if(this.colisionaConPaleta()){
			this.ejecutar();
			this.destroy();			
		}else if(this.getY()>this.getGame().getDisplayHeight())
			this.destroy();	
		
		super.update(deltaState);
	}
	
	public boolean colisionaConPaleta(){
		Arkanoid arkanoid = (Arkanoid) this.getGame();
		Paleta paleta = arkanoid.getPaleta();
		
		return CollisionDetector.INSTANCE.collidesCircleAgainstRect
				(this.getX(), this.getY(), this.diameter/2, paleta.getX(), paleta.getY(), 
						paleta.getAppearance().getWidth(),paleta.getAppearance().getHeight());
	}

}
